<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: XmlSimple::Cache</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">XmlSimple::Cache</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1_0_11/xmlsimple_rb.html">
                vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
A simple cache for XML documents that were already transformed by xml_in.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000116">new</a>&nbsp;&nbsp;
      <a href="#M000122">restore_mem_copy</a>&nbsp;&nbsp;
      <a href="#M000120">restore_mem_share</a>&nbsp;&nbsp;
      <a href="#M000118">restore_storable</a>&nbsp;&nbsp;
      <a href="#M000121">save_mem_copy</a>&nbsp;&nbsp;
      <a href="#M000119">save_mem_share</a>&nbsp;&nbsp;
      <a href="#M000117">save_storable</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000116" class="method-detail">
        <a name="M000116"></a>

        <div class="method-heading">
          <a href="#M000116" class="method-signature">
          <span class="method-name">new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates and initializes a <a href="Cache.html#M000116">new</a> <a
href="Cache.html">Cache</a> object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000116-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000116-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 20</span>
20:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
21:       <span class="ruby-ivar">@mem_share_cache</span> = {}
22:       <span class="ruby-ivar">@mem_copy_cache</span>  = {}
23:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000122" class="method-detail">
        <a name="M000122"></a>

        <div class="method-heading">
          <a href="#M000122" class="method-signature">
          <span class="method-name">restore_mem_copy</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Restores a data structure from a memory cache. If restoring the data
structure failed for any reason, nil will be returned.
</p>
<table>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000122-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000122-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 87</span>
87:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_mem_copy</span>(<span class="ruby-identifier">filename</span>)
88:       <span class="ruby-identifier">data</span> = <span class="ruby-identifier">get_from_memory_cache</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-ivar">@mem_share_cache</span>)
89:       <span class="ruby-identifier">data</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">data</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">nil?</span>
90:       <span class="ruby-identifier">data</span>
91:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000120" class="method-detail">
        <a name="M000120"></a>

        <div class="method-heading">
          <a href="#M000120" class="method-signature">
          <span class="method-name">restore_mem_share</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Restores a data structure from a shared memory cache. You should consider
these elements as &quot;read only&quot;. If restoring the data structure
failed for any reason, nil will be returned.
</p>
<table>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000120-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000120-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 67</span>
67:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_mem_share</span>(<span class="ruby-identifier">filename</span>)
68:       <span class="ruby-identifier">get_from_memory_cache</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-ivar">@mem_share_cache</span>)
69:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000118" class="method-detail">
        <a name="M000118"></a>

        <div class="method-heading">
          <a href="#M000118" class="method-signature">
          <span class="method-name">restore_storable</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Restores a data structure from a file. If restoring the data structure
failed for any reason, nil will be returned.
</p>
<table>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000118-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000118-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 41</span>
41:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_storable</span>(<span class="ruby-identifier">filename</span>)
42:       <span class="ruby-identifier">cache_file</span> = <span class="ruby-identifier">get_cache_filename</span>(<span class="ruby-identifier">filename</span>)
43:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">cache_file</span>)
44:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">cache_file</span>).<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">filename</span>).<span class="ruby-identifier">to_i</span>
45:       <span class="ruby-identifier">data</span> = <span class="ruby-keyword kw">nil</span>
46:       <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cache_file</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">data</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">f</span>) }
47:       <span class="ruby-identifier">data</span>
48:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000121" class="method-detail">
        <a name="M000121"></a>

        <div class="method-heading">
          <a href="#M000121" class="method-signature">
          <span class="method-name">save_mem_copy</span><span class="method-args">(data, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Copies a data structure to a memory cache.
</p>
<table>
<tr><td valign="top">data:</td><td>Data structure to be copied.

</td></tr>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000121-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000121-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 77</span>
77:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_mem_copy</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">filename</span>)
78:       <span class="ruby-ivar">@mem_share_cache</span>[<span class="ruby-identifier">filename</span>] = [<span class="ruby-constant">Time</span><span class="ruby-operator">::</span><span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">data</span>)]
79:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000119" class="method-detail">
        <a name="M000119"></a>

        <div class="method-heading">
          <a href="#M000119" class="method-signature">
          <span class="method-name">save_mem_share</span><span class="method-args">(data, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves a data structure in a shared memory cache.
</p>
<table>
<tr><td valign="top">data:</td><td>Data structure to be saved.

</td></tr>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000119-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000119-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 56</span>
56:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_mem_share</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">filename</span>)
57:       <span class="ruby-ivar">@mem_share_cache</span>[<span class="ruby-identifier">filename</span>] = [<span class="ruby-constant">Time</span><span class="ruby-operator">::</span><span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">data</span>]
58:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000117" class="method-detail">
        <a name="M000117"></a>

        <div class="method-heading">
          <a href="#M000117" class="method-signature">
          <span class="method-name">save_storable</span><span class="method-args">(data, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves a data structure into a file.
</p>
<table>
<tr><td valign="top">data:</td><td>Data structure to be saved.

</td></tr>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000117-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000117-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 31</span>
31:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_storable</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">filename</span>)
32:       <span class="ruby-identifier">cache_file</span> = <span class="ruby-identifier">get_cache_filename</span>(<span class="ruby-identifier">filename</span>)
33:       <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cache_file</span>, <span class="ruby-value str">&quot;w+&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">f</span>) }
34:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>